﻿using System;
using Epm.AppLogic.Framework;
using msBsc.Xsd.DataTds;
using System.Data;
using System.Web;
using msBsc.Cls;

namespace msBsc.AppLogic.DataAlc
{
    /// <summary>
    /// 用户注册
    /// </summary>
    public class CBizCustomerRegister : CustBizObject
    {
        private CDmDjkCustomerRegister m_CDmDjkCustomerRegister = new CDmDjkCustomerRegister();
        private CDmDjkCustomerRegister oDmDjkCustomerRegister
        {
            get { return m_CDmDjkCustomerRegister; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public CBizCustomerRegister()
            : base()
        {
            this.DataObj = new CDbAccess();
            this.DataObj.Init(this.m_CDmDjkCustomerRegister.DJK_CUSTOMER_REGISTER);
            this.TableName = this.DataObj.TableName;
            this.DataObj.KeyField = this.DataObj.Fields["CUSTOMER_REGISTER_ID"];
        }

        /// <summary>
        /// 新增记录前的处理
        /// </summary>
        /// <param name="drw">新增数据行</param>
        /// <returns>true/false</returns>
        /// <remarks>
        /// 生成ID值
        /// </remarks>
        protected override bool BeforeRowAdded(DataRow drw)
        {
            if (drw[this.KeyFieldName].ToString().Length < 10)
            {
                drw[this.KeyFieldName] = this.DataObj.NewID();
            }

            return true;
        }

        /// <summary>
        /// 记录修改前检验
        /// </summary>
        /// <param name="drw">当前记录</param>
        /// <returns>>校验合法，返回值为true,否则返回false</returns>
        /// <remarks>
        /// ID不允许修改,并把此修改操作记录到BSE_MODIFY_HISTORY表中
        /// </remarks>
        protected override bool BeforeRowModified(DataRow drw)
        {
            //ID不容许修改
            if (drw[this.KeyFieldName].ToString() != drw[this.KeyFieldName, DataRowVersion.Original].ToString())
            {
                Exception e = new Exception(this.TableName + "CUSTOMER_REGISTER_ID" + this.KeyFieldName + "字段不允许被修改");
                throw e;
            }
            return true;
        }
        protected override bool BeforeRowDeletedR(DataRow drw)
        {
            //using (msBsc.AppLogic.DataAlc.CBizShpPageColumn objtem = new CBizShpPageColumn())
            //{
            //    DataSet ds = objtem.SelectByPageNo(this.GetRowStr(drw, KeyFieldName));
            //    for (int i = ds.Tables[0].Rows.Count - 1; i >= 0; i--)
            //    {
            //        ds.Tables[0].Rows[i].Delete();
            //    }
            //    objtem.Update(ds);
            //} 
            return true;
        }

        protected override bool AfterRowAdded(DataRow drw)
        {
            //new msBsc.AppLogic.DataAlc.CBizCustomerBaseInfo().AddCustomerBaseInfo(drw["CUSTOMER_REGISTER_ID"].ToString(), drw["CUSTOMER_REGISTER_ACCOUNT"].ToString());

            return true;
        }

        protected override bool AfterRowModified(DataRow drw)
        {
            return true;
        }

        protected override bool AfterRowDeletedR(DataRow drw)
        {
            return true;
        }

        #region 用户注册
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="custAccount">用户账号</param>
        /// <param name="cusPwd">用户密码</param>
        /// <param name="invatationCode">邀请码(可为空)</param>
        /// <returns>提示信息</returns>
        public string[] AddCustomerInfo(string custAccount, string cusPwd, string invatationCode)
        {
            if (string.IsNullOrEmpty(custAccount) ||
                string.IsNullOrEmpty(cusPwd))
            {
                return new string[] { "FALSE", "用户名或密码为空！" };
            }

            if (!msBsc.Cls.CommValiCollection.IsEmail(custAccount))
            {
                return new string[] { "FALSE", "用户账号必须是邮箱！" };
            }

            if (cusPwd.Length < 6 || cusPwd.Length > 16)
            {
                return new string[] { "FALSE", "密码长度必须在6至16位之间" };
            }
            DataSet ds1 = GetCustoemrByAccount(custAccount);
            if (ds1.Tables[0].Rows.Count > 0)
            {
                return new string[] { "FALSE", "该用户名已存在" };
            }


            System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
            transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            transactionOption.Timeout = new TimeSpan(0, 10, 0);
            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
            {

                DataSet ds = new CDmDjkCustomerRegister();
                DataRow dr = ds.Tables[0].NewRow();

                dr["CUSTOMER_REGISTER_ID"] = this.DataObj.NewID();
                dr["CUSTOMER_REGISTER_PWD"] = msBsc.AppLogic.Cfg.DesCry.encMe(cusPwd, "zbhpass");

                dr["CUSTOMER_CLIENT_CODE"] = msBsc.SvRef.ApplicationConst.Const.GetNewSerialNo("CUSTOMER_CLIENT_CODE", "", 8);
                dr["CUSTOMER_ACCOUNT_TYPE"] = 5;
                dr["CUSTOMER_REGISTER_TIME"] = this.dtCurrDateTime;

                dr["CUSTOMER_INVITATION_CODE"] = msBsc.SvRef.ApplicationConst.Const.GetNewSerialNo("CUSTOMER_INVITATION_CODE", "", 16);
                dr["ACCOUNT_REGISTER_IP"] = msBsc.Cls.CommValiCollection.GetIp();
                dr["ACCOUNT_USING_STATUS"] = 1;
                dr["ACCOUNT_LOGIN_STATUS"] = 1;
                dr["CUSTOMER_DEFAULT_PIC"] = "/UpLoad/Djack/djack.jpg";
                dr["CUSTOMER_SOURCE_PIC"] = "/UpLoad/Djack/djack.jpg";
                dr["ACCOUNT_IS_ACTIVATED"] = 0;
                dr["CUSTOMER_REGISTER_ACCOUNT"] = custAccount;
                dr["CUSTOMER_NICK"] = custAccount;
                dr["BE_INVITATION_CODE"] = string.IsNullOrEmpty(invatationCode) ? "4d8e9272189bf98d" : invatationCode;
                dr["ACCOUNT_ACTIVATION_CODE"] = msBsc.SvRef.ApplicationConst.Const.GenerateStrId();
                dr["ACCOUNT_IS_DELETED"] = 0;

                ds.Tables[0].Rows.Add(dr);
                this.Update(ds);

                new msBsc.AppLogic.DataAlc.CBizCustomerBaseInfo().AddCustomerBaseInfo(dr["CUSTOMER_REGISTER_ID"].ToString(), dr["CUSTOMER_REGISTER_ACCOUNT"].ToString());
                ts.Complete();
                return new string[] { "OK", dr["ACCOUNT_ACTIVATION_CODE"].ToString() };
            }
        }

        /// <summary>
        /// 修改用户密码为加密
        /// </summary>
        /// <returns></returns>
        public bool CryCustomerPwd1()
        {

            DataSet ds = this.DataObj.QueryBySQL("SELECT * FROM DJK_CUSTOMER_REGISTER WHERE CUSTOMER_ACCOUNT_RMK IS NULL AND CUSTOMER_REGISTER_TIME>'2015/4/12  11:20:44'");
            ds.Tables[0].TableName = "DJK_CUSTOMER_REGISTER";

            if (ds.Tables[0].Rows.Count <= 0)
            {
                return false;
            }

            for (int i = ds.Tables[0].Rows.Count - 1; i >= 0; i--)
            {
                ds.Tables[0].Rows[i]["CUSTOMER_REGISTER_PWD"] = msBsc.AppLogic.Cfg.DesCry.encMe(ds.Tables[0].Rows[i]["CUSTOMER_REGISTER_PWD"].ToString(), "zbhpass");

            }
            this.Update(ds);
            return true;
        }

        #endregion

        #region 用户激活
        /// <summary>
        /// 用户激活
        /// </summary>
        /// <param name="userAccount">用户账号</param>
        /// <param name="activationCode">激活码</param>
        /// <returns></returns>
        public string[] UserActivation(string cusAccount, string activationCode)
        {
            if (string.IsNullOrEmpty(cusAccount) ||
                string.IsNullOrEmpty(activationCode))
            {
                return new string[] { "FALSE", "用户名或激活码不能为空" };
            }
            DataSet ds = ExistsCodeByAccount(cusAccount, activationCode);
            if (ds.Tables[0].Rows.Count <= 0)
            {
                return new string[] { "FALSE", "用户激活码不正确" };
            }
            DataRow dr = ds.Tables[0].Rows[0];
            if (Convert.ToInt32(dr["ACCOUNT_IS_ACTIVATED"]) == 1)
            {
                return new string[] { "FALSE", "用户已激活" };
            }
            dr["ACCOUNT_IS_ACTIVATED"] = 1;
            //ds.Tables[0].Rows.Add(dr);
            ds.Tables[0].TableName = this.TableName;
            this.Update(ds);

            return new string[] { "TRUE", "用户激活成功" };
        }

        /// <summary>
        /// 判断用户激活码
        /// </summary>
        /// <param name="custAccount">用户账号</param>
        /// <param name="activationCode">激活码</param>
        /// <returns></returns>
        public DataSet ExistsCodeByAccount(string custAccount, string activationCode)
        {
            if (string.IsNullOrEmpty(custAccount) ||
                string.IsNullOrEmpty(activationCode))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("ACCOUNT", ParameterDirection.Input, EDbType.String, 50, custAccount.Replace("'", "").Replace(",", "','")));
            parmCollection.Add(new CDbParm("CODE", ParameterDirection.Input, EDbType.String, 50, activationCode.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT * FROM DJK_CUSTOMER_REGISTER WHERE CUSTOMER_REGISTER_ACCOUNT =@ACCOUNT AND ACCOUNT_ACTIVATION_CODE=@CODE", parmCollection);
            return ds;
        }

        #endregion

        #region 找回密码
        /// <summary>
        /// 找回密码
        /// </summary>
        /// <param name="userAccount">用户账号</param>
        /// <param name="newPassword">用户新密码</param>
        /// <returns></returns>
        public string[] EditUserPassword(string userAccount, string newPassword)
        {
            #region 基本验证
            if (string.IsNullOrEmpty(userAccount))
            {
                return new string[] { "FALSE", "账号不能为空" };
            }
            if (!CommValiCollection.IsEmail(userAccount))
            {
                return new string[] { "FALSE", "账号只能是邮箱格式" };
            }
            if (string.IsNullOrEmpty(newPassword))
            {
                return new string[] { "FALSE", "密码不能为空" };
            }
            if (newPassword.Length < 6 ||
                newPassword.Length > 25)
            {
                return new string[] { "FALSE", "密码必须是6-25位之间" };
            }
            #endregion

            //判断该用户是否存在
            DataSet ds = GetCustoemrByAccount(userAccount);
            if (ds.Tables[0].Rows.Count <= 0)
            {
                return new string[] { "FALSE", "该用户不存在" };
            }
            ds.Tables[0].Rows[0]["CUSTOMER_REGISTER_PWD"] = msBsc.AppLogic.Cfg.DesCry.encMe(newPassword, "zbhpass");
            ds.Tables[0].TableName = this.TableName;
            this.Update(ds);
            return new string[] { "TRUE", "修改密码成功" };
        }
        #endregion

        #region 查询用户注册信息

        /// <summary>
        /// 查询游客信息
        /// </summary>
        /// <param name="djkId">游客ID</param>
        /// <returns>CUSTOMER_NICK:游客昵称,CUSTOMER_DEFAULT_PIC：头像</returns>
        public DataSet SelectCustomerByRegisterId(string cusId)
        {
            if (string.IsNullOrEmpty(cusId))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("CUSID", ParameterDirection.Input, EDbType.String, 36, cusId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT *
    FROM DJK_CUSTOMER_REGISTER
    WHERE CUSTOMER_REGISTER_ID=@CUSID", parmCollection);
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }


        /// <summary>
        /// 根据用户条件查询用户信息
        /// </summary>
        /// <param name="whereCondition"></param>
        /// <param name="startTime"></param>
        /// <param name="stopTime"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public DataSet GetUserInfoByConditions(string whereCondition, string startTime, string stopTime, string userName, string employeeInviCode)
        {
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("wherecondition", ParameterDirection.Input, EDbType.String, 100, whereCondition));
            parmCollection.Add(new CDbParm("starttime", ParameterDirection.Input, EDbType.String, 100, startTime));
            parmCollection.Add(new CDbParm("stoptime", ParameterDirection.Input, EDbType.String, 100, stopTime));
            parmCollection.Add(new CDbParm("username", ParameterDirection.Input, EDbType.String, 100, userName));
            parmCollection.Add(new CDbParm("employeeinvicode", ParameterDirection.Input, EDbType.String, 100, employeeInviCode));

            DataSet ds = this.DataObj.QueryBySP("DJK_SELECT_DJACK_INFO_FOR_VIEW", parmCollection);
            return ds;
        }


        /// <summary>
        /// 判断用户昵称是否唯一
        /// </summary>
        /// <param name="userNickName">用户昵称</param>
        /// <param name="userId">用户编号</param>
        /// <returns>用户昵称是否唯一(true:唯一，false:不唯一)</returns>
        public DataSet IsNickNameUnique(string userNickName, string userId)
        {
            if (string.IsNullOrEmpty(userId) ||
                string.IsNullOrEmpty(userNickName))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("UserName", ParameterDirection.Input, EDbType.String, 36, userNickName.Replace("'", "").Replace(",", "','")));
            parmCollection.Add(new CDbParm("UserId", ParameterDirection.Input, EDbType.String, 36, userId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT 1 FROM DJK_CUSTOMER_REGISTER 
WHERE CUSTOMER_NICK=@UserName AND CUSTOMER_REGISTER_ID<>@UserId", parmCollection);
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }

        /// <summary>
        /// 根据用户账号查询用户信息
        /// </summary>
        /// <param name="custAccount">用户账号</param>
        /// <returns>查询结果</returns>
        public DataSet GetCustoemrByAccount(string custAccount)
        {
            if (string.IsNullOrEmpty(custAccount))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("ACCOUNT", ParameterDirection.Input, EDbType.String, 50, custAccount.Replace("'", "").Replace(",", "','")));


            DataSet ds = this.DataObj.QueryBySQL(@"SELECT * FROM DJK_CUSTOMER_REGISTER WHERE CUSTOMER_REGISTER_ACCOUNT =@ACCOUNT", parmCollection);
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }


        /// <summary>
        /// 根据用户id查询用户帐号激活信息
        /// </summary>
        /// <param name="custId"></param>
        /// <returns></returns>
        public DataSet GetCustomerById(string custId)
        {
            if (string.IsNullOrEmpty(custId))
            {
                return null;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("custId", ParameterDirection.Input, EDbType.String, 36, custId.Replace("'", "").Replace(",", "','")));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT CUSTOMER_REGISTER_ID,CUSTOMER_REGISTER_ACCOUNT,CUSTOMER_REGISTER_PWD,BE_INVITATION_CODE,ACCOUNT_ACTIVATION_CODE,ACCOUNT_IS_ACTIVATED FROM DJK_CUSTOMER_REGISTER WHERE CUSTOMER_REGISTER_ID =@custId", parmCollection);
            ds.Tables[0].TableName = this.TableName;
            return ds;
        }



        #endregion

        /// <summary>
        /// 记录点击量
        /// </summary>
        /// <param name="inviteCode">邀请码</param>
        public void CustomerClick(string inviteCode)
        {
            if (string.IsNullOrEmpty(inviteCode))
            {
                inviteCode = "Self";
            }
            using (msBsc.AppLogic.DataAlc.CBizCustomerViews objCBizCustomerViews = new CBizCustomerViews())
            {
                objCBizCustomerViews.AddCustomerViewRecord(inviteCode, "Register");
            }
        }

        /// <summary>
        /// 用户设置支付密码
        /// </summary>
        /// <param name="innerPwd">支付密码</param>
        /// <returns>结果：[是否为首次设置,设置结果]</returns>
        public string[] SetInnerPayPwd(string innerPwd, bool isSetPwd)
        {
            if (string.IsNullOrEmpty(innerPwd))
            {
                return new string[] { "", "支付密码不能为空" };
            }

            if (innerPwd.Length < 6 || innerPwd.Length > 16)
            {
                return new string[] { "", "支付密码长度必须在6~16位之间" };
            }

            DataSet ds = this.DataObj.QueryBySQL(@"SELECT * FROM DJK_CUSTOMER_REGISTER WHERE CUSTOMER_REGISTER_ID='" + msBsc.SvRef.UserInfo.Operator + "'");
            ds.Tables[0].TableName = this.TableName;

            if (ds == null || ds.Tables[0].Rows.Count <= 0)
            {
                return new string[] { "", "用户信息有误" };
            }

            if (ds.Tables[0].Rows[0]["CUSTOMER_REGISTER_PWD"].ToString() == msBsc.AppLogic.Cfg.DesCry.encMe(innerPwd, "zbhpass"))
            {
                return new string[] { "", "支付密码不能和登录密码相同" };
            }

            if (ds.Tables[0].Rows[0]["CUSTOMER_PAY_INNERPWD"] != DBNull.Value
                && !string.IsNullOrEmpty(ds.Tables[0].Rows[0]["CUSTOMER_PAY_INNERPWD"].ToString()))
            {
                if (!isSetPwd)
                {
                    return new string[] { "TRUE", "您已设置支付密码,无需重复设置" };
                }

                ds.Tables[0].Rows[0]["CUSTOMER_PAY_INNERPWD"] = msBsc.AppLogic.Cfg.DesCry.encMe(innerPwd, "zbhpass");
                ds.Tables[0].Rows[0]["CUSTOMER_LAST_MDINNERPWDDT"] = this.dtCurrDateTime;
                this.Update(ds);

                return new string[] { "FALSE", "OK" };
            }

            ds.Tables[0].Rows[0]["CUSTOMER_PAY_INNERPWD"] = msBsc.AppLogic.Cfg.DesCry.encMe(innerPwd, "zbhpass");
            ds.Tables[0].Rows[0]["CUSTOMER_SET_INNERPWDDT"] = this.dtCurrDateTime;
            ds.Tables[0].Rows[0]["CUSTOMER_LAST_MDINNERPWDDT"] = this.dtCurrDateTime;
            this.Update(ds);

            return new string[] { "TRUE", "OK" };
        }

        /// <summary>
        /// 判断账户是否设置了支付密码
        /// </summary>
        /// <returns>string[]:index0:结果;index1:提示信息;index2:错误代码</returns>
        public string[] CustIsSetInnerPayPwd()
        {
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT CUSTOMER_PAY_INNERPWD FROM DJK_CUSTOMER_REGISTER WHERE CUSTOMER_REGISTER_ID='" + msBsc.SvRef.UserInfo.Operator + "'");

            if (ds == null
                || ds.Tables[0].Rows.Count <= 0)
            {
                return new string[] { "FALSE", "当前无账号登陆，请登陆", "01" };
            }

            if (ds.Tables[0].Rows[0]["CUSTOMER_PAY_INNERPWD"] == DBNull.Value)
            {
                return new string[] { "FALSE", "您尚未设置支付密码。请设置支付密码后，再进行支付账号绑定。", "02" };
            }
            return new string[] { "TRUE" };
        }


        /// <summary>
        /// 获取聊天中的用户信息
        /// </summary>
        /// <param name="userid">用户id</param>
        /// <returns>DataTable</returns>
        /// Author:蒲崇彬
        /// Creation date:2015-8-3 17:04
        public DataTable GetUserInfo(string userid)
        {
            if (string.IsNullOrEmpty(userid))
            {
                return null;
            }

            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("userid", ParameterDirection.Input, EDbType.String, 36, userid));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT CUSTOMER_REGISTER_ID,CUSTOMER_NICK,CUSTOMER_DEFAULT_PIC,ACCOUNT_IS_DELETED
    FROM DJK_CUSTOMER_REGISTER
    WHERE CUSTOMER_REGISTER_ID=@userid", parmCollection);

            if (ds == null || ds.Tables[0].Rows.Count < 1)
            {
                return null;
            }
            return ds.Tables[0];
        }

        /// <summary>
        /// 获取地接客 资料
        /// </summary>
        /// <param name="account">帐号</param>
        /// Author:蒲崇彬
        /// Creation date:2015-8-4 15:11
        public DataTable GetDjkUserInfo(string account)
        {
            if (string.IsNullOrEmpty(account))
            {
                return null;
            }

            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("account", ParameterDirection.Input, EDbType.String, 36, "%" + account + "%"));
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT [CUSTOMER_REGISTER_ID],[CUSTOMER_REGISTER_ACCOUNT],CUSTOMER_NICK,CUSTOMER_DEFAULT_PIC
FROM [dbo].[DJK_CUSTOMER_REGISTER] WHERE  CUSTOMER_ACCOUNT_TYPE=2 AND [CUSTOMER_REGISTER_ACCOUNT] like @account", parmCollection);

            if (ds == null || ds.Tables[0].Rows.Count < 1)
            {
                return null;
            }
            return ds.Tables[0];
        }

        /// <summary>
        /// 平台注册
        /// </summary>
        /// <returns></returns>
        public string[] PlatRegister()
        {
            return new string[] { "TRUE", "注册成功" };
        }



        /// <summary>
        /// 区域代理注册
        /// </summary>
        /// <param name="custAccount">注册手机号</param>
        /// <param name="cusPwd">注册密码（手机号后6位）</param>
        /// <param name="userPric">用户头像</param>
        /// <param name="identityCard">身份证 照片</param>
        /// <param name="realName">真实姓名</param>
        /// <param name="birth">生日</param>
        /// <param name="credentialsNo">身份证号码</param>
        /// <param name="countryId">代理 地区（国）</param>
        /// <param name="crtyid">代理 地区（城市）</param>
        /// <param name="distinationId">代理 地区（地区）</param>
        /// <param name="phone">座机号码</param>
        /// <param name="mobile">手机号码</param>
        /// <param name="qq">QQ</param>
        /// <param name="wechatNo">微信号码</param>
        /// <param name="bankType">银行类型</param>
        /// <param name="bankAccount">银行帐号</param>
        /// <param name="gender">性别</param>
        /// <param name="nick">昵称</param>
        /// <param name="credentialsType">证件类型</param>
        /// <returns></returns>
        /// Author:蒲崇彬
        /// Creation date:2015-8-31 17:15
        public string[] ProxyRegister(string custAccount, string cusPwd, string userPric, string identityCard, string realName, string birth, string credentialsNo, string countryId, string crtyid, string distinationId, string phone, string mobile, string qq, string wechatNo, string bankType, string bankAccount, string gender, string nick, string credentialsType)
        {
            if (string.IsNullOrEmpty(custAccount) ||
                string.IsNullOrEmpty(cusPwd))
            {
                return new string[] { "FALSE", "用户名或密码为空！" };
            }

            if (cusPwd.Length < 6 || cusPwd.Length > 16)
            {
                return new string[] { "FALSE", "密码长度必须在6至16位之间" };
            }
            DataSet ds1 = GetCustoemrByAccount(custAccount);
            if (ds1.Tables[0].Rows.Count > 0)
            {
                return new string[] { "FALSE", "该手机号码已注册" };
            }
            string userid = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(userid))
            {
                return new string[] { "FALSE", "请先登录后再添加用户" };
            }


            System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
            transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            transactionOption.Timeout = new TimeSpan(0, 10, 0);
            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
            {

                DataSet ds = new CDmDjkCustomerRegister();
                DataRow dr = ds.Tables[0].NewRow();

                dr["CUSTOMER_REGISTER_ID"] = this.DataObj.NewID();
                dr["CUSTOMER_REGISTER_PWD"] = msBsc.AppLogic.Cfg.DesCry.encMe(cusPwd, "zbhpass");

                dr["CUSTOMER_CLIENT_CODE"] = msBsc.SvRef.ApplicationConst.Const.GetNewSerialNo("CUSTOMER_CLIENT_CODE", "", 8);
                dr["CUSTOMER_ACCOUNT_TYPE"] = 1;
                dr["CUSTOMER_REGISTER_TIME"] = this.dtCurrDateTime;

                dr["CUSTOMER_INVITATION_CODE"] = msBsc.SvRef.ApplicationConst.Const.GetNewSerialNo("CUSTOMER_INVITATION_CODE", "", 16);
                dr["ACCOUNT_REGISTER_IP"] = msBsc.Cls.CommValiCollection.GetIp();
                dr["ACCOUNT_USING_STATUS"] = 1;
                dr["ACCOUNT_LOGIN_STATUS"] = 1;
                dr["CUSTOMER_DEFAULT_PIC"] = userPric;
                dr["CUSTOMER_SOURCE_PIC"] = userPric;
                dr["ACCOUNT_IS_ACTIVATED"] = 0;
                dr["CUSTOMER_REGISTER_ACCOUNT"] = custAccount;
                dr["CUSTOMER_NICK"] = nick;
                dr["BE_INVITATION_CODE"] = "4d8e9272189bf98d";
                dr["ACCOUNT_ACTIVATION_CODE"] = msBsc.SvRef.ApplicationConst.Const.GenerateStrId();
                dr["ACCOUNT_IS_DELETED"] = 0;

                dr["ACCOUNT_IS_ACTIVATED"] = 1;
                //添加人
                dr["INITIAL_USR"] = userid;
                ds.Tables[0].Rows.Add(dr);
                this.Update(ds);

                string[] messages = new msBsc.AppLogic.DataAlc.CBizCustomerBaseInfo().AddCustomerBaseInfo(dr["CUSTOMER_REGISTER_ID"].ToString(), identityCard, realName, credentialsNo, gender, birth, distinationId, crtyid, countryId, mobile, phone, qq, wechatNo, bankType, bankAccount, credentialsType);
                if (Convert.ToBoolean(messages[0]))
                {
                    ts.Complete();
                    return new string[] { "TRUE", "注册成功" };
                }

                return new string[] { "OK", messages[1] };
            }
        }
        /// <summary>
        /// 区域代理 修改
        /// </summary>
        /// <param name="cusId">用户id</param>
        /// <param name="userPric">用户头像</param>
        /// <param name="identityCard">身份证 照片</param>
        /// <param name="realName">真实姓名</param>
        /// <param name="birth">生日</param>
        /// <param name="credentialsNo">身份证号码</param>
        /// <param name="countryId">代理 地区（国）</param>
        /// <param name="crtyid">代理 地区（城市）</param>
        /// <param name="distinationId">代理 地区（地区）</param>
        /// <param name="phone">座机号码</param>
        /// <param name="mobile">手机号码</param>
        /// <param name="qq">QQ</param>
        /// <param name="wechatNo">微信号码</param>
        /// <param name="bankType">银行类型</param>
        /// <param name="bankAccount">银行帐号</param>
        /// <param name="gender">性别</param>
        /// <param name="nick">昵称</param>
        /// <param name="credentialsType">证件类型</param>
        /// <returns></returns>
        /// Author:蒲崇彬
        /// Creation date:2015-8-31 18:00
        public string[] UpdateProxyRegister(string cusId, string userPric, string identityCard, string realName, string birth, string credentialsNo, string countryId, string crtyid, string distinationId, string phone, string mobile, string qq, string wechatNo, string bankType, string bankAccount, string gender, string nick, string credentialsType)
        {
            string userid = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(userid))
            {
                return new string[] { "FALSE", "请先登录后再添加用户" };
            }
            //获取用户信息
            DataSet ds = SelectCustomerByRegisterId(cusId);
            if (ds.Tables[0].Rows.Count < 0)
            {
                return new string[] { "FALSE", "该用户不存在" };
            }

            System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
            transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            transactionOption.Timeout = new TimeSpan(0, 10, 0);
            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
            {
                DataRow dr = ds.Tables[0].Rows[0];

                dr["CUSTOMER_DEFAULT_PIC"] = userPric;
                dr["CUSTOMER_SOURCE_PIC"] = userPric;
                dr["CUSTOMER_NICK"] = nick;

                this.Update(ds);

                string[] messages = new msBsc.AppLogic.DataAlc.CBizCustomerBaseInfo().UpdateCustomerBaseInfo(cusId, identityCard, realName, credentialsNo, gender, birth, distinationId, crtyid, countryId, mobile, phone, qq, wechatNo, bankType, bankAccount, credentialsType);
                if (Convert.ToBoolean(messages[0]))
                {
                    ts.Complete();
                    return new string[] { "TRUE", "修改成功" };
                }

                return new string[] { "FALSE", messages[1] };
            }
        }
        /// <summary>
        /// 为代理添加地接客
        /// </summary>
        /// <param name="djkName">地接客姓名</param>
        /// <param name="countryId">所在地国家</param>
        /// <param name="cityId">所在地城市</param>
        /// <param name="destinationId">所在地目的地</param>
        /// <param name="telPhone">联系电话</param>
        /// <param name="serviceArea">服务区域</param>
        /// <param name="tencentQQ">QQ号码</param>
        /// <param name="weChatNo">微信号码</param>
        /// <param name="agentId">代理编号</param>
        /// <returns>结果：string[]:index0:是否成功，index1:原因</returns>
        /// Author:刘魏
        /// Creation date:2015-9-1 15:10
        public string[] AddAgentDjack(string djkName, string countryId, string cityId, string destinationId, string telPhone, string serviceArea, string tencentQQ, string weChatNo, string agentId)
        {
            DataSet ds1 = GetCustoemrByAccount(telPhone);
            if (ds1.Tables[0].Rows.Count > 0)
            {
                return new string[] { "FALSE", "该用户名已存在" };
            }

            string Id = this.DataObj.NewID();
            DataSet ds = new CDmDjkCustomerRegister();
            DataRow dr = ds.Tables[0].NewRow();

            dr["CUSTOMER_REGISTER_ID"] = Id;
            dr["CUSTOMER_REGISTER_ACCOUNT"] = telPhone;
            dr["CUSTOMER_REGISTER_PWD"] = msBsc.AppLogic.Cfg.DesCry.encMe(telPhone.Substring(telPhone.Length - 6), "zbhpass");
            dr["CUSTOMER_REGISTER_TIME"] = this.dtCurrDateTime;
            dr["CUSTOMER_ACCOUNT_TYPE"] = 3;
            dr["CUSTOMER_NICK"] = djkName.Substring(0, 1) + "师傅";
            dr["CUSTOMER_CLIENT_CODE"] = msBsc.SvRef.ApplicationConst.Const.GetNewSerialNo("CUSTOMER_CLIENT_CODE", "", 8);
            dr["ACCOUNT_USING_STATUS"] = 1;
            dr["ACCOUNT_LOGIN_STATUS"] = 0;
            dr["ACCOUNT_IS_ACTIVATED"] = 1;
            dr["ACCOUNT_IS_DELETED"] = 0;
            dr["INITIAL_DT"] = this.dtCurrDateTime;
            dr["INITIAL_USR"] = msBsc.SvRef.UserInfo.Operator;
            dr["PWD_IS_MODIFIED"] = 0;
            dr["FACCOUNT_ID"] = agentId;
            dr["ACCOUNT_GROUP_ID"] = 0;
            ds.Tables[0].Rows.Add(dr);


            System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
            transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            transactionOption.Timeout = new TimeSpan(0, 10, 0);
            using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
            {


                this.Update(ds);
                using (msBsc.AppLogic.DataAlc.CBizCustomerBaseInfo objCBizCustomerBaseInfo = new CBizCustomerBaseInfo())
                {
                    objCBizCustomerBaseInfo.AddAgentDjackBase(Id, djkName, countryId, cityId, destinationId, telPhone, serviceArea, tencentQQ, weChatNo);
                }


                ts.Complete();
            }

            return new string[] { "TRUE" };
        }

        /// <summary>
        /// 判断代理地接客是否已修改密码
        /// </summary>
        /// <returns></returns>
        /// Author:刘魏
        /// Creation date:2015-9-15 16:00
        public bool CustomerIsModifyPwd()
        {
            DataSet ds = this.DataObj.QueryBySQL(@"SELECT * FROM DJK_CUSTOMER_REGISTER A WHERE A.CUSTOMER_REGISTER_ID='" + msBsc.SvRef.UserInfo.Operator + "'");

            if (ds == null
                || ds.Tables[0].Rows.Count <= 0)
            {
                return false;
            }

            bool isModified = false;

            bool.TryParse(ds.Tables[0].Rows[0]["PWD_IS_MODIFIED"].ToString(), out isModified);

            return isModified;
        }

        /// <summary>
        /// 修改代理地接客密码
        /// </summary>
        /// <param name="newPwd">新密码</param>
        /// <returns>strinn[],index0:True|False;index1:Reason</returns>
        /// Author:刘魏
        /// Creation date:2015-9-15 16:05
        public string[] ModifyAgentDjackPwd(string newPwd)
        {
            if (string.IsNullOrWhiteSpace(newPwd))
            {
                return new string[] { "False", "新密码不能为空" };
            }

            if (newPwd.Length < 6 || newPwd.Length > 16)
            {
                return new string[] { "False", "新密码长度必须在6~16位之间" };
            }

            if (msBsc.SvRef.UserInfo.OperType != "3")
            {
                return new string[] { "False", "此类型账号不允许在此修改密码" };
            }

            DataSet ds = SelectById(msBsc.SvRef.UserInfo.Operator);

            if (ds == null
                || ds.Tables[0].Rows.Count <= 0)
            {
                return new string[] { "False", "该用户不存在" };
            }

            bool isModified = false;

            bool.TryParse(ds.Tables[0].Rows[0]["PWD_IS_MODIFIED"].ToString(), out isModified);

            if (isModified)
            {
                return new string[] { "False", "该账号密码已成功修改过" };
            }


            if (msBsc.AppLogic.Cfg.DesCry.encMe(newPwd.Trim(), "zbhpass") == ds.Tables[0].Rows[0]["CUSTOMER_REGISTER_PWD"].ToString())
            {
                return new string[] { "False", "新密码不能与原密码相同" };
            }

            ds.Tables[0].Rows[0]["CUSTOMER_REGISTER_PWD"] = msBsc.AppLogic.Cfg.DesCry.encMe(newPwd.Trim(), "zbhpass");
            ds.Tables[0].Rows[0]["PWD_IS_MODIFIED"] = 1;
            ds.Tables[0].Rows[0]["FIRST_USE_DT"] = this.dtCurrDateTime;

            this.Update(ds);

            return new string[] { "True", "修改成功" };
        }

        /// <summary>
        /// 是否启用 用户
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="type"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public string[] UpdateStatus(string userid, int type, int status)
        {
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("userid", ParameterDirection.Input, EDbType.String, 36, userid));
            parmCollection.Add(new CDbParm("type", ParameterDirection.Input, EDbType.Integer, 32, type));

            DataSet ds = this.DataObj.QueryBySQL(@"SELECT * FROM DJK_CUSTOMER_REGISTER WHERE CUSTOMER_REGISTER_ID=@userid AND CUSTOMER_ACCOUNT_TYPE=@type", parmCollection);
            if (ds == null || ds.Tables[0].Rows.Count < 1)
            {
                return new string[] { "false", "该用户不存在" };
            }
            ds.Tables[0].Rows[0]["ACCOUNT_IS_DELETED"] = status;
            ds.Tables[0].TableName = this.TableName;
            this.Update(ds);

            return new string[] { "true", "修改成功" };

        }
    }
}
